package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.service.OrderListService;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/orderlist")
public class OrderListController {
    @Reference
    private OrderListService orderListService;

    //分页查询
    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean) {
        String[] selectDate = queryPageBean.getSelectDate();
        PageResult pageResult = orderListService.pageQuery(
                selectDate,
                queryPageBean.getSelectStatus(),
                queryPageBean.getSelectType(),
                queryPageBean.getQueryString(),
                queryPageBean.getPageSize(),
                queryPageBean.getCurrentPage());
        return pageResult;
    }

    //开关修改状态
    @RequestMapping("/changeStatus")
    public Result chanStatus(@RequestBody Map<String, Object> map) {
        try {
            orderListService.changeStatus(map);
            return new Result(true, MessageConstant.QUERY_ORDER_SUCCESS);

        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.QUERY_ORDER_FAIL);
        }
    }

    //删除预约信息
    @RequestMapping("/delete")
    public Result delete(Integer orderId){
        System.out.println();
        try {
            orderListService.delete(orderId);
            return new Result(true,"删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return  new Result(false,"网络错误");
        }

    }

}